
#include <cflow.h>
#include <argp.h>
#include <argp-version-etc.h>
#include <progname.h>
#include <stdarg.h>
#include <parser.h>
#include <version-etc.h>


int is_function(char str[14]){
	char *string;
    char *find_regex_expr;      //查找用的正则表达式
    char *find_string;          //查找到的子串
    int start;                  //查找到的子串的起始位置
    int length;                 //子串的长度

    string=malloc(256);
    strcpy(string,str);
    find_regex_expr=”r[aou]t”;     //意思是三个字符r?t, 第二个字符只能是a,o,u之一

    printf(“RegexFind Example: string=%s, regex=%s/n”,string,find_regex_expr);

    //Regex查找示例
    while (1==RegexFind(string,find_regex_expr,&start, &length))
      {
         //找到后，从string截取出子串
         find_string=ExtractString(string, start, length);
         if (find_string!=NULL)
           {
              printf(“Found %s/n”, find_string);
              free(find_string); //由于ExtractString时申请了内存，此处释放子串内存
           }
         string=string+length; //将指针指向下一个位置，以便继续查找
		 return 1;
      }
	
	return 0;
}

int
main(int argc, char **argv)
{
	
	FILE *fp;
	int len;
	char *data;
	char str1[14] = "main";
	
	//读取文件
	fp=fopen("/opt/test/test.c","w+");
	fseek(fp,0,SEEK_END);
	len=ftell(fp);
	fseek(fp,0,SEEK_SET);
	data=(char*)malloc(len+1);
	fread(data,1,len,fp);
	fclose(fp);
	
	
	char *p = strstr(data,str1);
	printf("%s\n", p);
	
	
	//设置主函数执行到的行数
     int index = 0;

	//读取文件名
     set_program_name(argv[0]);
     argp_version_setup("test", program_authors);
     
	 
	 //绑定文本范围
     setlocale(LC_ALL, "");
     bindtextdomain(PACKAGE, LOCALEDIR);
     textdomain(PACKAGE);
     
	 //设定起止位置
     register_output("index", gnu_output_handler, NULL);
     register_output("posix", posix_output_handler, NULL);

     symbol_map = SM_FUNCTIONS|SM_STATIC|SM_UNDEFINED;

	//搜索主函数
     if (getenv("main")) {
	  if (select_output_driver("posix"))
	       error(1, 0, _("%s: No such output driver"), "posix");
	  output_init();
     }
	 
     
	 //搜索子函数
     str1 = sourcerc(&argc, &argv);
     if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
	  exit(1);

     if (print_option == 0 || is_function（str1） == 0)
	  print_option = PRINT_TREE;

     init();
	
	//输出树形文件
     if (arglist) {
	  struct linked_list_entry *p;

	  for (p = arglist->head; p; p = p->next) {
	       char *s = (char*)p->data;
	       if (s[0] == '-')
		    pp_option(s);
	       else if (source(s) == 0)
		    yyparse();
	  }
     }
     
     argc -= index;
     argv += index;

     while (argc--) {
	  if (source(*argv++) == 0)
	       yyparse();
     }

     if (input_file_count == 0)
	     error(1, 0, _("no input files"));

     output();
     return 0;
}







